<template>
  <el-container>
    <el-header class="per-header">
      <home-header/>
    </el-header>

    <search-header :search='true' isHome='true' class="per-search-content"/>

    <!--    'service_hall-content':$route.path === '/personCenter/service_hall'-->
    <el-container :class="{'el-content':true}">
      <el-aside style="width: 250px;">
        <div class="aside_wrapper">
          <div class="avatar">
            <img src="" alt="">
            <p>您好：</p>
          </div>
          <div class="user_info">
            <h3 class="user_name">{{userInfo.realName}}</h3>
            <p class="time">上次登录时间： {{userInfo.updateTime.substring(0,10)}}</p>
            <p class="server">业主服务中心>></p>
          </div>
        </div>
        <el-menu
            :default-active="$route.meta.active_path || $route.path"
            mode="vertical"
            router
            @open="handleOpen"
            :unique-opened="true"
            class="el-menu-vertical-demo"
        >
          <sidebar-item :menu="data"/>
        </el-menu>
      </el-aside>

      <!--      :class="{'el-main_hall':$route.path === '/personCenter/service_hall'}"-->
      <el-main style="padding:0 0 0 40px">
        <el-tabs v-model="activePage" @tab-click="handleClick">
          <el-tab-pane label="首页" name="home"/>
          <el-tab-pane label="账户管理" name="account"/>
        </el-tabs>
        <router-view/>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
  import SearchHeader from "@/components/searchHeader";
  import HomeHeader from "@/components/HomeHeader";
  import SidebarItem from "./components/SidebarItem";
  import {homeList, accountList} from "./docs"

  let userInfo = JSON.parse(localStorage.getItem('userInfo')) || {};
  export default {
    components: {
      SearchHeader,
      HomeHeader,
      SidebarItem
    },
    name: "",
    data() {
      return {
        activePage: '',
        data: [],
        userInfo
      }
    },
    provide() {
      return {
        userInfo: this.userInfo
      }
    },
    created() {
      this.activeMenu()
    },
    watch: {
      '$route.path'() {
        this.activeMenu()
      }
    },
    methods: {
      activeMenu() {
        let isActive = accountList.findIndex(item => item.path === this.$route.path) >= 0;
        this.data = isActive ? accountList : homeList;
        this.activePage = isActive ? 'account' : 'home';
      },
      handleOpen(key, keyPath) {
        console.log(key, keyPath);
      },
      handleClick() {
        if (this.activePage === 'home') {
          this.$router.history.push("/personCenter/service_hall"); // 默认跳转
          this.data = homeList;
        } else if (this.activePage === 'account') {
          this.data = accountList;
          this.$router.history.push("/personCenter/account");
        }
      },
      handleNodeClick(item) {
        this.$refs.tree.setCheckedKeys([]);


        this.$refs.tree.setCheckedNodes([
          {
            label: '发布需求信息',
            path: '/personCenter/demand_rel',
          },
        ]);

        this.$router.history.push(item.path)
      }
    }
  }
</script>

<style scoped lang="scss">
  .per-header {
    padding: 0;
  }

  .el-content {
    max-width: 1000px;
    margin: 0 auto;


    .aside_wrapper {
      height: 200px;
      padding: 20px 10px;
      box-sizing: border-box;
      color: #fff;
      background: linear-gradient(150deg, #4D99CD, #1B689F);
      box-shadow: 0px 1px 3px 0px rgba(73, 73, 73, 0.3);
      border-radius: 3px;

      .avatar {
        margin-bottom: 28px;

        img {
          width: 33px;
          height: 33px;
          background: #FFFFFF;
          border: 2px solid #FFF8ED;
          border-radius: 50%;
          object-fit: cover;
          vertical-align: middle;
        }

        p {
          font-size: 16px;
          font-weight: 500;
          color: #FFFFFF;
          display: inline-block;
          margin-left: 15px;
        }

      }

      .user_info {
        margin-left: calc(33px + 15px);

        .user_name {
          font-size: 16px;
          font-weight: 500;
          color: #FFFFFF;
        }

        .time {
          font-size: 12px;
          font-weight: 500;
          color: #FFFFFF;
          margin: 9px 0 8px 0;
        }

        .server {
          width: 110px;
          font-size: 12px;
          background: linear-gradient(150deg, #EFDEBD, #E9D2AC);
          box-shadow: 0px 1px 3px 0px rgba(73, 73, 73, 0.3);
          border-radius: 3px;
          line-height: 14px;
          font-weight: 500;
          color: #9F7834;
          padding: 4px;
          cursor: pointer;
        }
      }
    }
  }


  /* 服务大厅*/
  .service_hall-content {
    max-width: 1200px;
    width: 1200px;
  }

  .el-main {
    width: calc(1000px - 250px);
  }

  .el-main_hall {
    width: 850px;
    margin-right: -20px;
  }


  ::v-deep .el-tabs__item {
    font-size: 16px;
  }

  ::v-deep .el-tabs__nav-wrap {
    border-bottom: 1px solid rgba(73, 73, 73, 0.1);
  }

  ::v-deep .el-tabs__nav-wrap::after {
    background-color: transparent;
  }

  ::v-deep .el-tree {
    margin-top: 20px;
    color: #333333;

    .el-tree-node__content {
      border-bottom: 1px solid #F1F1F1;

      height: 42px;
      transition: all 0.1s;
    }

    .el-tree-node__expand-icon {
      color: #333333
    }
  }

  ::v-deep .el-submenu__title {
    height: 43px;
    line-height: 43px;
    list-style: none;
    position: relative;
    white-space: nowrap;
    border-bottom: 1px solid #F1F1F1;
  }

  ::v-deep .el-submenu [class^=el-icon-], ::v-deep .el-menu-item [class^=el-icon-] {
    font-size: 12px;
    color: #000;
  }

</style>
<style lang="scss">
  .per-search-content.bg-liner {
    background: #fff;
    border-bottom: 1px solid #91919173;
    margin-bottom: 8px;

    .item-content {
      width: 1000px;
    }
  }

  .el-menu-item-group__title {
    padding: 0;
  }

  .el-submenu_title, .el-submenu__title {
    height: 43px;
    line-height: 43px;
    list-style: none;
    position: relative;
    white-space: nowrap;
    border-bottom: 1px solid #F1F1F1;
  }

  .el-menu-item {
    border-bottom: 1px solid #F1F1F1;
    height: 44px;
    line-height: 44px;
  }


  .el-submenu.is-active .el-submenu__title {
    border-bottom-color: transparent;
  }

  .el-menu {
    border-right: none;
  }

  .el-menu-vertical-demo {
    margin-left: -20px;
    margin-top: 10px;
  }

  .el-submenu__icon-arrow {
    display: none;
  }


  .el-menu-item.is-active {
    background: #2D80B4 !important;
    color: #fff !important;

    i {
      color: #fff !important;
    }
  }
</style>
